package com.lancer.jvm.oom;

/**
 * 限制每个线程的内存大小，内存设置越大，报错越快
 * VM Args: -Xss2G
 * @Author lancer
 */
public class JavaVMStackOOM {
    /**
     * 让线程不终止
     */
    private void dontStop(){
        while (true){
        }
    }
    /**
     * 不断创建线程
     */
    public void stackLeakByThread(){
        long i = 1;
        while (true){
            //
            System.out.println(i++);
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    dontStop();
                }
            });
        }
    }

    public static void main(String[] args) {
        JavaVMStackOOM oom = new JavaVMStackOOM();
        oom.stackLeakByThread();
    }
}
